package com.developer.platform.application.command;

import cn.hutool.core.bean.BeanUtil;
import com.developer.platform.application.command.cmd.TemplateAdd;
import com.developer.platform.application.command.cmd.TemplateUpdate;
import com.developer.platform.domain.Template;
import com.developer.platform.infrastructure.data.mapper.TemplateMapper;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2020-12-29
 */
@Component
public class TemplateCmdManager {

  private final TemplateMapper templateMapper;

  public TemplateCmdManager(
      TemplateMapper templateMapper) {
    this.templateMapper = templateMapper;
  }

  public void save(TemplateAdd templateAdd){
    Template template = new Template();
    BeanUtil.copyProperties(templateAdd, template);
    templateMapper.insert(template);
  }

  public void update(long id, TemplateUpdate templateUpdate){
    Template template = new Template(id);
    BeanUtil.copyProperties(templateUpdate, template);
    templateMapper.updateById(template);
  }

  public void delete(long id){
    templateMapper.deleteById(id);
  }

}
